import { Component, OnInit, ViewChild, Renderer2 } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { ApiService } from 'src/app/core/api';
import { Global } from 'src/app/core/global';
import { StorageService } from 'src/app/core/sotrage/storage.service';

@Component({
	templateUrl: './index.component.html',
	styleUrls: ['./index.component.less'],
})

export class GzComponent implements OnInit {
	type=0;
	uri = null;
	orderList=[];
	gList=[];
	pageNo = 1;
	userDel;
	gameId;
	toUrl = 'http://172.16.12.23:8080';
	@ViewChild("myBox",{ static: true }) _ifr1: any;
	stopListening: Function; 
	constructor( private router: Router, private global: Global, private api: ApiService, private sto: StorageService, private activedRoute: ActivatedRoute,private renderer: Renderer2,) {
		this.uri = this.activedRoute.snapshot.queryParams.url || 0;
	}

	ngAfterViewInit(){
		let ifrl = this._ifr1.nativeElement.contentWindow;
		this._ifr1.nativeElement.src = this.uri;
		let user = this.sto.get('user');
		let sto = this.sto;
		user.appId = '00001' ;
		user.appToken = 'appToken0001' ;
		window.onmessage = function(e){
			switch (e.data.type) {
				case 'gameOK':
						sto.set('host', e.data.data.host);
						ifrl.postMessage({type:"userToGame",data:user}, 'http://' + e.data.data.host) ;
					 break;
			 }
			
		};
	}
	ngOnInit() {
	}

}

